#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> substr_idx;
int main() {
    string a, b;
    cin >> a >> b;
    string& min_str = a.length() < b.length()?a:b;
    string& max_str = a.length() < b.length()?b:a;
    
    vector<substr_idx> substr_vecs;
    int min_length = 0;
    for (int i = 0; i < min_str.length(); ++i) {
        for (int j = 0; j < max_str.length();) {
            if (max_str[j] == min_str[i]) {
                int left, right;
                left = right = j;
                while(i+right-left < min_str.length() && (max_str[right] == min_str[i+right-left])) {
                    // if (right-left+1 > min_length) {
                    //     substr_vecs.push_back(substr_idx(left, right));
                    //     min_length = right-left+1;
                    // }
                    substr_vecs.push_back(substr_idx(left, right));
                    right++;
                }
                j = right+1;
            } else {
                j++;
            }
        }
    }
    // 需要十分注意排序的稳定性要求
    stable_sort(substr_vecs.begin(), substr_vecs.end(), [](const substr_idx& a, const substr_idx& b) {
        return (a.second-a.first) >= (b.second-b.first);
    });
    cout << max_str.substr(substr_vecs.front().first, substr_vecs.front().second-substr_vecs.front().first+1);
}

//jxjelkpmykawipycx
// cmeuvawlwvwxvljvshkoqrtxbywogdnsppuiuezfyliioplpzboanpmilhjqbsocyvhldqrzskjffuofkdzceeoswnmqwfhzbybfsrbkglhfaxxfjvslecjoopxhtfnoziplkuthiqvggnyijavoxcrczfwmqkpexcgiofwysgyiufcrvfdpicptfkvzhwxq